import React from 'react';
import './Login.scss'
import {Form,Input,Button,Modal} from 'antd'
import {useState} from 'react'
import { useNavigate } from 'react-router-dom';
import service from '../../api'
import { useDispatch } from 'react-redux';
const Login = () => {
    var [isModalOpen,setisModalOpen] = useState(false)
   var dispatch = useDispatch()
    //成功提交时候执行
    let navigate = useNavigate()
    var onFinish = async (values:any)=>{
        let res = await service.login.adminlogin(values)
        console.log('管理员登录',res.data);
        // console.log(res.data.data.token);
           dispatch({type:'SAVETOKEN',payload:res.data.data})
        
            navigate('/index')
        }
  
    return (
        <div className='login'>
           
           
         <Form className='form'
                onFinish={onFinish}
                style={{ maxWidth: 600 }}
                >
                 <p style={{textAlign:'center'}}>欢迎登录</p>
                 <p>账号</p>
                 <Form.Item
                name="adminname"
                rules={[{ required: true, message: '请输入登陆账号' }]}
                >
                    <Input placeholder='请登陆账号'/>
                </Form.Item>
                <p>密码</p>
                <Form.Item
                name="password"
                rules={[{ required: true, message: '请输入登陆密码' }]}
                >
                    <Input.Password placeholder='请登陆密码'/>
                </Form.Item>
                
                <Form.Item>
                    <Button type="primary" htmlType="submit" > 
                    登录
                    </Button>
                
                </Form.Item>
            </Form>
        {/* 弹框 */}
        {/* <Button type="primary" onClick={showModal}>
        Open Modal
      </Button>
      <Modal title="Basic Modal" open={isModalOpen}  >
        <p>Some contents...</p>
        <p>Some contents...</p>
        <p>Some contents...</p>
      </Modal> */}
        </div>
    );
};

export default Login;